
package com.bawei.module_live.data


import com.google.gson.*
import java.lang.reflect.Type


data class LiveShopData(
    val current: Int,
    val pages: Int,
    val records: List<Record>,
    val size: Int,
    val total: Int
)

data class Record(
    val brandCode: String,
    val brandName: String,
    val createTime: String,
    val goodsCode: String,
    val group: Group,
    val id: Int,
    val mainImgUrl: String,
    val marketPriceFee: Int,
    val modelCode: String,
    val modelName: String,
    val operIdCreate: Any,
    val operIdMod: Any,
    val operNameCreate: String,
    val operNameMod: String,
    val productType: String,
    val purchasePrice: Int,
    val soldNum: Int,
    val title: String,
    val tlineCode: String,
    val tlineName: String,
    val updateTime: String
)

data class Group(
    val code: String,
    val createTime: String,
    val id: Int,
    val name: String,
    val operIdCreate: Int,
    val operIdMod: Int,
    val operNameCreate: String,
    val operNameMod: String,
    val parentId: Int,
    val parentName: String,
    val remark: String,
    val sort: Int,
    val type: String,
    val updateTime: String
)
class LiveShopDataDeserializer : JsonDeserializer<LiveShopData> {
    override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): LiveShopData {
        // 兼容 data 为 "" 或 null
        if (json.isJsonNull || (json.isJsonPrimitive && json.asJsonPrimitive.isString && json.asString.isBlank())) {
            return LiveShopData(0, 0, emptyList(), 0, 0)
        }
        // 只有是对象时才正常解析
        if (json.isJsonObject) {
            return context.deserialize(json, typeOfT)
        }
        // 其它情况兜底
        return LiveShopData(0, 0, emptyList(), 0, 0)
    }
}
